const isButton = function(menuType: string) {
    return menuType === 'b';
}

const isMenu = function(menuType: string) {
    return menuType === 'm';
}

const isDir = function(menuType: string) {
    return menuType === 'd';
}

const statusBool = function (status: string) {
    return status === 'on';
};

const statusString = function (bool: boolean) {
    return bool?'on':'off';
};

const atoRetainB = function (originObj:object,targetObj:object){
    for(let key in targetObj) {
        targetObj[key as keyof typeof targetObj] = originObj[key  as keyof typeof originObj]
    }
}

const buildRoleOptions = function (arr:any){
    const optionArr: { label: string; value: any; }[] = [];
    Object.keys(arr).forEach((item) => {
        const option = {
            label: arr[item].roleName,
            value:arr[item].roleCode
        }
        optionArr.push(option)
    })
    return optionArr;
}

const buildRoleOptions1 = function (arr:any){
    const optionArr: { label: string; value: any; }[] = [];
    Object.keys(arr).forEach((item) => {
        const option = {
            label: arr[item].roleName + "（"+ arr[item].roleCode  +"）",
            value: arr[item].id
        }
        optionArr.push(option)
    })
    return optionArr;
}

const buildBeanNameOptions = function (arr:any){
    const optionArr: { label: string; value: any; }[] = [];
    Object.keys(arr).forEach((item) => {
        const option = {
            label: item,
            value: item
        }
        optionArr.push(option)
    })
    return optionArr;
}

const buildMethodNameOptions = function (arr:any){
    const optionArr: { label: string; value: any; }[] = [];
    if (Object.is(arr,null) || Object.is(arr,undefined)){
        return optionArr;
    }
    Object.keys(arr).forEach((item) => {
        const option = {
            label: arr[item].methodDesc,
            value: arr[item].methodName
        }
        optionArr.push(option)
    })
    return optionArr;
}


const copyEditObj = function (obj: object, ...args:string[]) {
    const toEditBo = JSON.parse(JSON.stringify(obj));
    if (args.length <= 0) {
        return obj;
    }
    for (let i = 0; i < args.length; i++) {
        delete toEditBo[args[i]];
        toEditBo[args[i]] = (toEditBo[args[i]]).code;
    }
    return toEditBo;
}

const getMethodParamList = function (localJobDocument:any,obj:any){
    return localJobDocument[obj.beanName][obj.methodName].taskParamList;
}

export {
    isButton,isMenu,isDir,statusBool,statusString,atoRetainB,buildRoleOptions,buildRoleOptions1,buildBeanNameOptions,
    buildMethodNameOptions,getMethodParamList,copyEditObj
}